Ext.namespace("App.Base.SystemMainFrame");

App.Base.SystemMainFrame.LoginWindow = function(){
	var loginForm = null;
	var loginWin = null;

	var doLogin = function(){
		Ext.getCmp('SYS_OP_CMD').setValue(App.Base.common.param.OP_CMD_LOGIN_VERIFY);
		if (Ext.getCmp('loginForm').form.isValid()) 
		{
			Ext.getCmp('loginForm').form.submit({
				waitTitle: '用户登录',
				waitMsg: '服务器正在验证用户信息，请稍候...',
				url: App.Base.common.param.SYSTEM_USER_LOGIN_URL,
				success: function(form, action) {
					if (action.result.msg.ReturnCode == App.Base.common.param.REQ_SUCCESS)
					{
						loginWin.close();
						//loginWin.destroy();
						window.location = App.Base.common.param.SYSTEM_MAINFRAME_URL;
					}
					else
					{
						Ext.MessageBox.alert('登录失败', action.result.msg.Description);
					}
				},
				failure: function(form, action) {
					Ext.MessageBox.alert('登录失败', "服务器暂停服务，请稍候重试");
				},
				scope: this
			});
		}
		else
		{
			Ext.MessageBox.alert('系统提示', "请正确输入用户登录信息");
		}
	};

	var doReset = function(){
		Ext.getCmp('loginForm').getForm().reset();
	};
	
	return {
		init : function(){
			Ext.QuickTips.init();
						
			loginWin = new Ext.Window({
				//el: 'loginWin',
				title: '用户登录',
				width: 296,
				height: 180,
				plain: true,
				resizable: false,
				collapsible: true,
				closable: false,
				minimizable: false,
				constrain: true,
				modal: true,
				iconCls: 'x-systemmanage-verifytitle',
				layout: 'fit',
				items: [
					new Ext.form.FormPanel({
						id: 'loginForm',
						bodyStyle: 'padding-top:18px',
						defaultType: 'textfield',
						defaults: {
							allowBlank : false,
							selectOnFocus : true
						},
						labelAlign: 'right',
						labelWidth: 56,
						labelPad: 0,
						frame: true,
						layout: 'form',
						items: [{
							id: 'userId',
							name: 'userId',
							fieldLabel: '<font color="blue">账 号</font>',
							blankText: '用户账号不能为空',
							cls: 'x-systemmanage-verifyuser'
						}, {
							name: 'userPwd',
							fieldLabel: '<font color="blue">密 码</font>',
							blankText: '用户密码不能为空',
							inputType: 'password',
							minLength: 6,
							minLengthText: '密码至少输入6位字符',
							cls: 'x-systemmanage-verifypassword',
							enableKeyEvents: true,
							listeners: {
								keydown: function(o, e){
									if (e.getCharCode() == 13)
									{
										doLogin();
									}
								},
								scope: this
							}
						}, {
							id: 'SYS_OP_CMD',
							name: 'SYS_OP_CMD',
							hidden: true,
							hideLabel: true
						}]
					})				
				],
				buttonAlign: 'right',
				buttons: [{
					text: '确 定',
					handler: doLogin,
					scope: this
				},{
					text: '重 置',
					handler: doReset,
					scope: this
				}]
			});
				
			loginWin.show();

			Ext.getCmp("userId").focus(true, true);
		}
	};
}();

Ext.onReady(App.Base.SystemMainFrame.LoginWindow.init, App.Base.SystemMainFrame.LoginWindow);